package ar.edu.uba.fi.jmit.monitorengine.backend.client.controller;

import java.util.List;

import ar.edu.uba.fi.jmit.monitorengine.backend.client.Monitorengine;
import ar.edu.uba.fi.jmit.monitorengine.backend.client.StatisticsService;
import ar.edu.uba.fi.jmit.monitorengine.backend.client.StatisticsServiceAsync;
import ar.edu.uba.fi.jmit.monitorengine.backend.client.view.ReceiverStatsPanel;
import ar.edu.uba.fi.jmit.monitorengine.backend.shared.dto.StatisticPair;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class ReceiverStatsController {
	
	private Monitorengine monitorengine;
	
	private ReceiverStatsPanel panel;
	
	private StatisticsServiceAsync statistcsService = GWT.create(StatisticsService.class);

	public ReceiverStatsController(Monitorengine monitorengine) {
		this.monitorengine = monitorengine;
		this.panel = monitorengine.getReceiverStatsPanel();
	}

	public void showReceiverStats() {
		monitorengine.showReceiverStats();
		statistcsService.getAllReceiverStatistics(new AsyncCallback<List<StatisticPair>>() {

			@Override
			public void onFailure(Throwable arg0) {
				GWT.log("Failure", arg0);
				//TODO
			}

			@Override
			public void onSuccess(List<StatisticPair> stats) {
				panel.showStatistics(stats);
			}
			
		});
		
	}

}
